package com.project.controller;

import com.github.pagehelper.PageInfo;
import com.project.bean.ClassBean;
import com.project.service.IClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;


/**
 * @author lyl
 * description:
 */
@Controller
@RequestMapping("class")
public class ClassController {
    @Autowired
    private IClassService iClassService;

    @RequestMapping("findAllByPage")
    public String finAllByPage(@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo, Model model) {
        PageInfo<ClassBean> pageInfo = iClassService.findAllByPage(pageNo);
        model.addAttribute("pageInfo", pageInfo);
        return "/html/class/index.html";
    }

    @RequestMapping("add")
    public String add(ClassBean classBean) {
        iClassService.add(classBean);
        return "redirect:/class/findAllByPage";
    }

    @RequestMapping("del")
    public String del(int id) {
        iClassService.del(id);
        return "redirect:/class/findAllByPage";
    }

    @RequestMapping("findById")
    public String findById(int id, Model model) {
        ClassBean classBean = iClassService.findById(id);
        model.addAttribute("classObj", classBean);
        return "/html/class/update.html";
    }

    @RequestMapping("update")
    public String update(int id, String teacher) {
        iClassService.updateClassTeacher(id, teacher);
        return "redirect:/class/findAllByPage";
    }
}

